package com.hspedu.date_;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/2/5
 * @time 17:19
 */
public class LocalDateTime_ {
    public static void main(String[] args) {

        LocalDateTime ldt = LocalDateTime.now();
        System.out.println(ldt);
        System.out.println("ldt.getYear() = " + ldt.getYear());
        System.out.println("ldt.getMonth() = " + ldt.getMonth());
        System.out.println("ldt.getMonthValue() = " + ldt.getMonthValue());
        System.out.println("ldt.getDayOfMonth() = " + ldt.getDayOfMonth());
        System.out.println("ldt.getHour() = " + ldt.getHour());
        System.out.println("ldt.getMinute() = " + ldt.getMinute());
        System.out.println("ldt.getSecond() = " + ldt.getSecond());

        LocalDate now = LocalDate.now();
        System.out.println(now);

        LocalTime now1 = LocalTime.now();
        System.out.println(now1);

        //使用DateTimeFormatter格式化
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH时mm分ss秒");
        System.out.println("dtf.format(ldt) = " + dtf.format(ldt));

        String str = "2022年02月01日 00时00分00秒";
        System.out.println(dtf.format(dtf.parse(str)));
    }
}
